package com.ruoyi.system.service.msg.enricher;

import com.ruoyi.system.entity.ConstructionProjectDO;
import com.ruoyi.system.entity.MsgPushTaskDO;
import com.ruoyi.system.entity.ConstructionProjectItemDO;
import com.ruoyi.system.enums.MsgTypeEnum;
import com.ruoyi.system.service.ConstructionProjectService;
import com.ruoyi.system.service.IConstructionItemService;
import com.ruoyi.system.service.msg.MsgDetailEnricher;
import com.ruoyi.system.vo.H5MsgDetailVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 事项验收消息详情丰富器
 * 用于丰富事项验收类型消息的详情信息，包括验收事项详情、阶段信息、验收模板等
 *
 * @author ruoyi
 * @since 2024-01-01
 */
@Component
public class AcceptItemMsgEnricher implements MsgDetailEnricher {

    @Resource
    private IConstructionItemService projectItemService;

    @Resource
    private ConstructionProjectService projectService;

    @Override
    public boolean supports(Integer msgType) {
        return Objects.equals(msgType, MsgTypeEnum.ACCEPTANCE_INFO.getCode());
    }

    @Override
    public void enrich(H5MsgDetailVO vo, MsgPushTaskDO task) {
        if (task.getBusinessId() == null || task.getBusinessId().trim().isEmpty()) {
            return;
        }
        ConstructionProjectItemDO projectItemDO = projectItemService.getById(Long.valueOf(task.getBusinessId()));
        ConstructionProjectDO constructionProjectDO = projectService.getById(projectItemDO.getProjectId());
        constructionProjectDO.setProjectItem(projectItemDO);
        vo.setConstructionProjectDO(constructionProjectDO);
    }
}


